/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import javax.persistence.CascadeType;
import javax.persistence.Temporal;
import javax.persistence.ManyToOne;

/**
 *
 * @author Julian's Lappy
 */
@Entity
public class MessageBox implements Serializable {
    private static long serialVersionUID = 1L;

    /**
     * @return the serialVersionUID
     */
    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    /**
     * @param aSerialVersionUID the serialVersionUID to set
     */
    public static void setSerialVersionUID(long aSerialVersionUID) {
        serialVersionUID = aSerialVersionUID;
    }
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long messageID;
    private Long receiverID;
    private String title;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date sendDate;
    private boolean broadcast;
    @ManyToOne(cascade={CascadeType.PERSIST})
    private SystemUser userID;
    
    
    
    public Long getId() {
        return getMessageID();
    }

    public void setId(Long id) {
        this.setMessageID(id);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getMessageID() != null ? getMessageID().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the messageID fields are not set
        if (!(object instanceof MessageBox)) {
            return false;
        }
        MessageBox other = (MessageBox) object;
        if ((this.getMessageID() == null && other.getMessageID() != null) || (this.getMessageID() != null && !this.messageID.equals(other.messageID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.MessageBox[ id=" + getMessageID() + " ]";
    }

    /**
     * @return the messageID
     */
    public Long getMessageID() {
        return messageID;
    }

    /**
     * @param messageID the messageID to set
     */
    public void setMessageID(Long messageID) {
        this.messageID = messageID;
    }

    /**
     * @return the receiverID
     */
    public Long getReceiverID() {
        return receiverID;
    }

    /**
     * @param receiverID the receiverID to set
     */
    public void setReceiverID(Long receiverID) {
        this.receiverID = receiverID;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the sendDate
     */
    public Date getSendDate() {
        return sendDate;
    }

    /**
     * @param sendDate the sendDate to set
     */
    public void setSendDate(Date sendDate) {
        this.sendDate = sendDate;
    }

    /**
     * @return the broadcast
     */
    public boolean isBroadcast() {
        return broadcast;
    }

    /**
     * @param broadcast the broadcast to set
     */
    public void setBroadcast(boolean broadcast) {
        this.broadcast = broadcast;
    }

    Date myStringToDate(String s) throws ParseException {
        DateFormat df = DateFormat.getInstance();
        SimpleDateFormat sdf = (SimpleDateFormat)df;
        sdf.applyPattern("dd MMM yyyy");
        return df.parse(s);
    }

    /**
     * @return the userID
     */
    public SystemUser getUserID() {
        return userID;
    }

    /**
     * @param userID the userID to set
     */
    public void setUserID(SystemUser userID) {
        this.userID = userID;
    }
    
}
